package ${commonPackageName}.utils;

import java.util.function.Supplier;

import ${commonPackageName}.enums.ExceptionEnum;
import ${commonPackageName}.exception.BusinessException;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;

/**
 * 断言工具
 * @author lizihao
 *
 */
public class AssertUtil {

	/**
	 * 判断是否空,空则抛异常 
	 * @param <T>
	 * @param <X>
	 * @param object 对象
	 * @param errorSupplier 需要抛的异常
	 * @return
	 * @throws X
	 */
	public static <T, X extends Throwable> T isNull(T object, Supplier<X> errorSupplier) throws X {
		if (null == object) {
			throw errorSupplier.get();
		}
		return object;
	}
	/**
	 * 判断是否非空,是则抛异常
	 * @param <X>
	 * @param object 检查对象
	 * @param errorSupplier 需要抛的异常
	 * @throws X
	 */
	public static <X extends Throwable> void isNotNull(Object object, Supplier<X> errorSupplier) throws X {
		if (null != object) {
			throw errorSupplier.get();
		}
	}
	
	/**
	 * 判断表达式是否true,false则抛异常
	 * @param <X>
	 * @param expression 表达式
	 * @param errorSupplier 需要抛的异常
	 * @throws X
	 */
	public static <X extends Throwable> void isTrue(boolean expression, Supplier<X> errorSupplier) throws X {
		if (expression) {
			throw errorSupplier.get();
		}
	}
	/**
	 * 表达式为false就抛异常
	 * @param <X>
	 * @param expression 表达式
	 * @param supplier 需要抛的异常
	 * @throws X
	 */
	public static <X extends Throwable> void isFalse(boolean expression, Supplier<? extends X> supplier) throws X {
		if (false == expression) {
			throw supplier.get();
		}
	}
}
